//
//  QueryDimVC.m
//  CJRailTransport
//
//  Created by Hank on 2018/1/15.
//  Copyright © 2018年 amplity. All rights reserved.
//
// 顶层按钮的宽度
#define TopBtnWidth    80
// 顶层按钮的高度
#define TopBtnHeight   88
// 顶层按钮的间隙
#define TopBtnSpacing  50

#import "QueryDimVC.h"
#import "QueryDimListVC.h"
#import "BasicNavigationController.h"
#import "UIButton+Expand.h"
#import "UIView+Expand.h"

@interface QueryDimVC ()<TYTabPagerControllerDataSource, TYTabPagerControllerDelegate>
// 分类数组
@property (nonatomic, strong) NSArray *sortArray;

@end

@implementation QueryDimVC

#pragma mark - lifeCycle
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // 加载栏目样式
        [self configurePagerStyles];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        // 加载栏目样式
        [self configurePagerStyles];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 把视图扩展到底部tabbar
    self.edgesForExtendedLayout = UIRectEdgeBottom;
    // 加载栏目按钮样式
    [self configureTabButtonPager];
    // 加载数据
    [self loadData];
    // 设置导航栏
    [self setNavC];
    // 设置界面属性
    [self setViewAttribute];
    // 设置圆角
    [self setRadius];
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    // 更改顶端滑动视图的位置
    self.tabBar.frame = CGRectMake((self.view.yj_width - TopBtnWidth * self.sortArray.count - TopBtnSpacing * (self.sortArray.count - 1)) / 2,  8 / 2 + 46, TopBtnWidth * self.sortArray.count + TopBtnSpacing * (self.sortArray.count - 1) + 1, TopBtnHeight - 48 - 8);
}

// 加载栏目样式
- (void)configurePagerStyles
{
    self.tabBarHeight = TopBtnHeight;
}

// 加载栏目按钮样式
- (void)configureTabButtonPager
{
    self.dataSource = self;
    self.delegate = self;
//    self.tabBar.backgroundColor = [UIColor redColor];
    self.tabBar.layout.barStyle = TYPagerBarStyleCoverView;
    self.tabBar.layout.progressColor = [UIColor whiteColor];
    self.tabBar.layout.progressBorderWidth = 0.5;
    self.tabBar.layout.progressBorderColor = DefaultRadiusGray;
    self.tabBar.layout.normalTextColor = [UIColor darkGrayColor];
    self.tabBar.layout.selectedTextColor = [UIColor darkGrayColor];
    self.tabBar.layout.normalTextFont = [UIFont systemFontOfSize:15];
    self.tabBar.layout.selectedTextFont = [UIFont systemFontOfSize:16];
    self.tabBar.layout.cellWidth = TopBtnWidth;
    self.tabBar.layout.cellSpacing = TopBtnSpacing;
    self.tabBar.layout.cellEdging = 0;
    self.tabBar.layout.adjustContentCellsCenter = YES;
}

#pragma mark - 导航栏
- (void)setNavC
{
    self.title = @"查询";
    // 设置导航栏颜色
    BasicNavigationController *nVC = (BasicNavigationController *)self.navigationController;
    nVC.themeColor = [UIColor whiteColor];
    nVC.tintColor = [UIColor darkGrayColor];
}

// 设置界面属性
- (void)setViewAttribute
{
    self.view.backgroundColor = [UIColor whiteColor];
}

#pragma mark - Radius
// 设置圆角
- (void)setRadius
{
    // 设置圆角
    [self.searchBg radiusView:5 backgroundColor:[UIColor clearColor] borderWidth:0.5 borderColor:DefaultRadiusGray];
}

#pragma mark - load data
// 加载数据
- (void)loadData
{
    self.sortArray = @[@"场站",@"路段"];
    // 刷新数据
    [self reloadData];
}

#pragma mark - textFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return YES;
}

#pragma mark - TYTabPagerControllerDataSource

- (NSInteger)numberOfControllersInTabPagerController {
    return _sortArray.count;
}

- (UIViewController *)tabPagerController:(TYTabPagerController *)tabPagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching {
    QueryDimListVC *queryDimListVC = [[QueryDimListVC alloc]init];
    queryDimListVC.index = index;
    return queryDimListVC;
}

- (NSString *)tabPagerController:(TYTabPagerController *)tabPagerController titleForIndex:(NSInteger)index {
    NSString *title = _sortArray[index];
    return title;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
